package Clonable;

public class Person implements Cloneable{//需要接口才能实现克隆
    public String name;
    public Money m;

    public Person() {
    }

    public Person(String name) {
        this.name = name;
        m  =new Money();
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {//重写的方法
        Person tmp = (Person) super.clone();
        tmp.m = (Money) this.m.clone();//这个才是克隆当前所指对象
        return tmp;
    }
}
